package test.demo.service.impl;

import com.alibaba.fastjson.JSON;
import test.demo.dto.PeopleExcel;
import test.demo.service.PersonTest;
import test.demo.utils.FileUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Service
public class PeopleTestService implements PersonTest {


    @Override
    public void exportTest(HttpServletResponse response) {



        List<PeopleExcel> peopleExcelList = new ArrayList<>();

        PeopleExcel myPeople = new PeopleExcel();
        myPeople.setName("大涛");
        myPeople.setPhone(17306);

        peopleExcelList.add(myPeople);

        /*
        * 调用导入导出工具类方法
        * */
        FileUtil.exportExcel(peopleExcelList,"test","people", PeopleExcel.class,"peopletest.xls",response);

    }

    @Override
    @Transactional
    public List<PeopleExcel> importTest() {

        String filePath = "E:\\peopletest.xls";
        //解析excel
        List<PeopleExcel> excelPersonList = FileUtil.importExcel(filePath,1,1,PeopleExcel.class);

        int size = excelPersonList.size();

        System.out.println("导入数据："+size);
        System.out.println(JSON.toJSONString(excelPersonList));

        return excelPersonList;
    }

}
